﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 预收清单
    /// </summary>
    public partial class Precollected: BusEntity
    {
        public Precollected()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 计划Id
        /// </summary>
        public string PlanId { set; get; }
        /// <summary>
        /// Bom清单Id
        /// </summary>
        public string BomTreeId { set; get; }
        /// <summary>
        /// 物料Id(冗余信息防定义阶段数据更改)
        /// </summary>
        public string MaterielId { set; get; }
        /// <summary>
        /// 物料规格Id(冗余信息防定义阶段数据更改)
        /// </summary>
        public string SpecId { set; get; }
        /// <summary>
        /// 物料编码(冗余信息防定义阶段数据更改)
        /// </summary>
        public string EleCode { set; get; }
        /// <summary>
        /// 物料编码(冗余信息防定义阶段数据更改)
        /// </summary>
        public string MaterieCode { set; get; }
        /// <summary>
        /// 物料名称(冗余信息防定义阶段数据更改)
        /// </summary>
        public string MaterieName { set; get; }
        /// <summary>
        /// 规格编码(冗余信息防定义阶段数据更改)
        /// </summary>
        public string SpecCode { set; get; }
        /// <summary>
        /// 规格名称(冗余信息防定义阶段数据更改)
        /// </summary>
        public string SpecName { set; get; }
        /// <summary>
        /// 预收数量
        /// </summary>
        public int Quantity { set; get; }
        /// <summary>
        /// 实收数量
        /// </summary>
        public int RealIncome { set; get; }
    }

    public partial class Precollected : BusEntity
    {
        public Plan PlanInfor { set; get; }

        public List<RealIncome> RealIncomes { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class PrecollectedTypeConfig : BusEntityTypeConfig<Precollected>, IEntityTypeConfiguration<Precollected>
    {
        public override void Configure(EntityTypeBuilder<Precollected> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.PlanInfor).WithMany(p => p.Precollecteds).HasForeignKey(p => p.PlanId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.PlanId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.BomTreeId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.MaterielId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SpecId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.MaterieCode).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SpecCode).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.MaterieName).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();  
            builder.Property(p => p.SpecName).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Quantity).IsRequired();
            builder.Property(p => p.RealIncome).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("预收清单");
            builder.Property(p => p.PlanId).HasComment("计划Id");
            builder.Property(p => p.BomTreeId).HasComment("Bom清单Id");
            builder.Property(p => p.MaterielId).HasComment("物料Id");
            builder.Property(p => p.EleCode).HasComment("电气编码");
            builder.Property(p => p.MaterieCode).HasComment("物料编码");
            builder.Property(p => p.MaterieName).HasComment("物料名称");
            builder.Property(p => p.SpecId).HasComment("物料编码");
            builder.Property(p => p.SpecName).HasComment("物料规格");
            builder.Property(p => p.Quantity).HasComment("预收数量");
            builder.Property(p => p.RealIncome).HasComment("实收数量");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
